#
# /etc/makepkg.conf
#

#########################################################################
# SOURCE ACQUISITION
#########################################################################
#
#-- The download utilities that makepkg should use to acquire sources
#  Format: 'protocol::agent'
DLAGENTS=('ftp::/usr/bin/curl -fC - --ftp-pasv --retry 3 --retry-delay 3 -o %o %u'
          'http::/usr/bin/curl -fLC - --retry 3 --retry-delay 3 -o %o %u'
          'https::/usr/bin/curl -fLC - --retry 3 --retry-delay 3 -o %o %u'
          'rsync::/usr/bin/rsync --no-motd -z %u %o'
          'scp::/usr/bin/scp -C %u %o')

# Other common tools:
# /usr/bin/snarf
# /usr/bin/lftpget -c
# /usr/bin/wget

#-- The package required by makepkg to download VCS sources
#  Format: 'protocol::package'
VCSCLIENTS=('bzr::bzr'
            'git::git'
            'hg::mercurial'
            'svn::subversion')

#########################################################################
# ARCHITECTURE, COMPILE FLAGS
#########################################################################
#
CARCH="x86_64"
CHOST="x86_64-pc-linux-gnu"

#-- Compiler and Linker Flags
# -march (or -mcpu) builds exclusively for an architecture
# -mtune optimizes for an architecture, but builds for whole processor family
#CPPFLAGS="-D_FORTIFY_SOURCE=2"
#orig: CFLAGS="-march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong"
#CFLAGS="-O2 -pipe -march=native -g0 -fno-var-tracking-assignments -fomit-frame-pointer -ftrack-macro-expansion=0 -fno-stack-protector -fPIC --param=ssp-buffer-size=4 -D_FORTIFY_SOURCE=2 -Wno-trigraphs"
CFLAGS="-pipe -march=native -Wno-trigraphs -fno-schedule-insns2 -fno-delete-null-pointer-checks -mtune=native -fomit-frame-pointer -Ofast -fno-fast-math -D_FORTIFY_SOURCE=2"
#14 sept. 2016: re-added fortify source!
#01 sept. 2016: removed: -flto  because at least in kernel compilation causes some compile errors!(but only when it's in extra args! not sense when it's only here!
#31 aug 2016: removed: -O3
#31 aug 2016: added: -Ofast
#hmm: strip: stQu66PX/vp9_alt_ref_aq.c.o: plugin needed to handle lto object  (in libvpx-git)
#added: -fomit-frame-pointer -O3
#src: http://linuxreviews.org/howtos/compiling/
#hmm:  #  warning _FORTIFY_SOURCE requires compiling with optimization (-O)
#removing: -D_FORTIFY_SOURCE=2 -O2
#added: -mtune=native -flto  src: https://gcc.gnu.org/wiki/LinkTimeOptimization
#removed 30 aug 2016: -fPIC  (if you re-add then add this: -flto -mtune=native src: https://stackoverflow.com/questions/15861759/how-much-overhead-can-the-fpic-flag-add )
#XXX: removed 18 aug 2016: -fstack-protector-strong -fno-omit-frame-pointer --param=ssp-buffer-size=4
#XXX: 05aug2016 removed: -ggdb -ftrack-macro-expansion=2 -fvar-tracking-assignments
#-fno-schedule-insns2 -fno-delete-null-pointer-checks #src: https://groups.google.com/d/msg/mozilla.dev.builds/kTqLzbdgGHk/iC8FVdFjBQAJ
#Note: utox fails with: -fsanitize=address
#-fsanitize=thread    cc1: error: -fsanitize=address and -fsanitize=kernel-address are incompatible with -fsanitize=thread

CPPFLAGS="${CFLAGS}"
CXXFLAGS="${CFLAGS}"
#added but not needed/used: CPPFLAGS="${CXXFLAGS}" apparently! using CFLAGS for now!
#CXXFLAGS="-march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong"
LDFLAGS="-Wl,-O1,--sort-common,--as-needed,-z,relro"
#-- Make Flags: change this for DistCC/SMP systems
#MAKEFLAGS="-j2" #T400
#MAKEFLAGS="-j4" #Z575
#XXX: was good for no distcc: MAKEFLAGS="-j$(nproc)" || MAKEFLAGS="-j4"  #any (with fallback!) - nproc is part of coreutils!
MAKEFLAGS="-j4"
#-j5 takes more time (78min vs 70min with -j4 for firefox-hg)
#-- Debugging flags
#XXX: Additional compiler flags appended to CFLAGS for use in debugging. (yeah, adding these to CFLAGS is a bad idea, it's better to just replace CFLAGS!)
#DEBUG_CFLAGS="-g -fvar-tracking-assignments"
#DEBUG_CFLAGS="-march=native -O1 -pipe -fstack-protector-strong --param=ssp-buffer-size=4 -D_FORTIFY_SOURCE=2 -Wno-trigraphs -fno-omit-frame-pointer -ftrack-macro-expansion=2 -ggdb -fvar-tracking-assignments -fPIC"
#DEBUG_CFLAGS="-fstack-protector-strong -fno-omit-frame-pointer -ftrack-macro-expansion=2 -ggdb -fvar-tracking-assignments -fPIC" #last
DEBUG_CFLAGS="--never-supposed-to-be-used blah blah"
#DEBUG_CXXFLAGS="-g -fvar-tracking-assignments"
DEBUG_CXXFLAGS="$DEBUG_CFLAGS"

#########################################################################
# BUILD ENVIRONMENT
#########################################################################
#
# Defaults: BUILDENV=(!distcc color !ccache check !sign)
#  A negated environment option will do the opposite of the comments below.
#
#-- distcc:   Use the Distributed C/C++/ObjC compiler
#-- color:    Colorize output messages
#-- ccache:   Use ccache to cache compilation
#-- check:    Run the check() function if present in the PKGBUILD
#-- sign:     Generate PGP signature file
#
#BUILDENV=(!distcc color ccache check !sign)
BUILDENV=(!distcc color ccache check !sign)

#XXX: manually added(they are seen in PKGBUILD! so it should work!)
CCACHE_SIZE="200G"                                                              
CCACHE_NOCOMPRESS=1  #because we're on a btrfs(lzo) filesystem
CCACHE_COMPRESSLEVEL=0
#needs installed: pacman -S ccache

if test "$0" == "/usr/bin/yaourt"; then
  cd /tmp/
fi

#
#-- If using DistCC, your MAKEFLAGS will also need modification. In addition,
#-- specify a space-delimited list of hosts running in the DistCC cluster.
#that's lmighty4 aka 3mighty4
#DISTCC_HOSTS="192.168.1.233/3 localhost/0"
#DISTCC_HOSTS="localhost/5 --localslots_cpp=8 192.168.1.233/3"
DISTCC_HOSTS="192.168.1.233/3 localhost/4" #localhost/5 --localslots_cpp=8 192.168.1.233/3"
#127.0.0.1/5"
#DISTCC_HOSTS="127.0.0.1/4 192.168.1.233/2" #doesn't seem to need the 127 one!
#DISTCC_HOSTS="@192.168.1.233/2"
#still tries port 22: DISTCC_SSH="ssh -i /home/z/.../T400/koe -p 802 -l a"
#^this has effect, it's in env when PKGBUILD-ing! but:
#FIXME: it's just that distcc still tries ssh on port 22

#
#-- Specify a directory for package building.
#BUILDDIR=/tmp/makepkg
BUILDDIR="`realpath ./makepkg_pacman`"  #auto-created by pacman!

#########################################################################
# GLOBAL PACKAGE OPTIONS
#   These are default values for the options=() settings
#########################################################################
#
# Default: OPTIONS=(strip docs !libtool !staticlibs emptydirs zipman purge !optipng !upx !debug)
#  A negated option will do the opposite of the comments below.
#
#-- strip:      Strip symbols from binaries/libraries
#-- docs:       Save doc directories specified by DOC_DIRS
#-- libtool:    Leave libtool (.la) files in packages
#-- staticlibs: Leave static library (.a) files in packages
#-- emptydirs:  Leave empty directories in packages
#-- zipman:     Compress manual (man and info) pages in MAN_DIRS with gzip
#-- purge:      Remove files specified by PURGE_TARGETS
#-- optipng: Optimize PNG images with optipng
#-- upx:        Compress binary executable files using UPX
#-- debug:      Add debugging flags as specified in DEBUG_* variables
#
#OPTIONS=(strip docs !libtool !staticlibs emptydirs zipman purge !optipng !upx !debug)
OPTIONS=(!strip docs !libtool !staticlibs emptydirs !zipman purge !optipng !upx !debug)
#XXX: not zipman due to using btrfs(lzo) already AND why waste cpu cycles/time then.
#XXX: debug disabled! do not use this variant! rather, just set CFLAGS and stuff inside PKGBUILD!
#XXX: strip disabled, using debug in CFLAGS by default! (but not debug flag!)

#-- File integrity checks to use. Valid: md5, sha1, sha256, sha384, sha512
#INTEGRITY_CHECK=(md5)
INTEGRITY_CHECK=(sha512)
#-- Options to be used when stripping binaries. See `man strip' for details.
STRIP_BINARIES="--strip-all"
#-- Options to be used when stripping shared libraries. See `man strip' for details.
STRIP_SHARED="--strip-unneeded"
#-- Options to be used when stripping static libraries. See `man strip' for details.
STRIP_STATIC="--strip-debug"
#-- Manual (man and info) directories to compress (if zipman is specified)
MAN_DIRS=({usr{,/local}{,/share},opt/*}/{man,info})
#-- Doc directories to remove (if !docs is specified)
DOC_DIRS=(usr/{,local/}{,share/}{doc,gtk-doc} opt/*/{doc,gtk-doc})
#-- Files to be removed from all packages (if purge is specified)
PURGE_TARGETS=(usr/{,share}/info/dir .packlist *.pod)

#########################################################################
# PACKAGE OUTPUT
#########################################################################
#
# Default: put built package and cached source in build directory
#
#-- Destination: specify a fixed directory where all packages will be placed
#PKGDEST=/home/packages
PKGDEST="`realpath ./packages_pacman`"
#-- Source cache: specify a fixed directory where source files will be cached
#SRCDEST=/home/sources
SRCDEST="`realpath ./sources_pacman`"
#-- Source packages: specify a fixed directory where all src packages will be placed
#SRCPKGDEST=/home/srcpackages
SRCPKGDEST="`realpath ./srcpackages_pacman`"
#-- Log files: specify a fixed directory where all log files will be placed
LOGDEST="`realpath ./makepkglogs_pacman`"

if test "$0" != "/usr/bin/yaourt" -a ! -e 'PKGBUILD'; then
  echo "Refusing to operate whilst no PKGBUILD exists in current dir: `pwd`"
  echo "See: /etc/makepkg.conf  (\$0 is $0)"
  exit 111
fi
mkdir -p -- "$PKGDEST" "$SRCDEST" "$SRCPKGDEST" "$LOGDEST"

#-- Packager: name/email of the person or organization building packages
#PACKAGER="John Doe <john@doe.com>"
PACKAGER="icanrealizeum"
#-- Specify a key to use for package signing
#GPGKEY=""

#########################################################################
# COMPRESSION DEFAULTS
#########################################################################
#
COMPRESSGZ=(gzip -c -f -n)
COMPRESSBZ2=(bzip2 -c -f)
#xz-git from the AUR now supports symmetric multiprocessing (SMP).
#src: https://wiki.archlinux.org/index.php/makepkg#Utilizing_multiple_cores_on_compression
COMPRESSXZ=(xz -T0 -c -z -)
COMPRESSLRZ=(lrzip -q)
COMPRESSLZO=(lzop -q)
COMPRESSZ=(compress -c -f)

#########################################################################
# EXTENSION DEFAULTS
#########################################################################
#
# WARNING: Do NOT modify these variables unless you know what you are
#          doing.
#
#PKGEXT='.pkg.tar.xz'
#SRCEXT='.src.tar.gz'
#XXX: don't waste CPU and time by compressing! (also we're on btrfs with lzo forced!)
PKGEXT='.pkg.tar'
SRCEXT='.src.tar'


# vim: set ft=sh ts=2 sw=2 et:
